package com.atguigu.rabbitmq.six;
import com.atguigu.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ReceiveLogsDirect02 {


    public static final String EXCHANGE_NAME = "direct_logs";


    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitMqUtils.getChanner();

        //声明一个交换机 直接交换机类型
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        //声明一个队列
        channel.queueDeclare("dsik", false, false, false, null);

        /**
         * 参数1:队列名
         * 参数2:交换机的名
         * 参数3:Routing Key
         */
        channel.queueBind("dsik", EXCHANGE_NAME, "errot");
//        channel.queueBind("console", EXCHANGE_NAME, "warning");


        //接收消息
        channel.basicConsume("dsik", true, (message, deilver) -> {
            System.out.println("R02消费的消息打印到控制台:" + new String(deilver.getBody(), "UTF-8"));
        }, message -> System.out.println("取消消费"));


    }


}